# Maintainer: Fabian Affolter <fabian@affolter-engineering.ch>
# Contributor: Fabian Affolter <fabian@affolter-engineering.ch>
# Contributor: Duncan Bellamy <dunk@denkimushi.com>
pkgname=jemalloc
pkgver=5.2.1
pkgrel=0
pkgdesc="general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support"
url="http://jemalloc.net"
arch="all"
license="custom"
makedepends="build-base autoconf libxslt docbook-xsl"
subpackages="$pkgname-dev $pkgname-doc"
source="https://github.com/jemalloc/jemalloc/releases/download/$pkgver/jemalloc-$pkgver.tar.bz2"
build() {
	local _pgs
	case "$CARCH" in
		x86|x86_64)	_pgs=12 ;;
		ppc64le)	export CPPFLAGS="$CPPFLAGS -maltivec -mabi=altivec" && _pgs=16 ;;
		*)		_pgs=16 ;;
	esac

	echo "$pkgver" > VERSION
	local _xslroot=$(find /usr/share/xml/docbook -iname "xsl-stylesheets-*")
	autoconf
	./configure \
		--enable-xmalloc \
		--prefix="$pkgdir"/usr \
		--localstatedir=/var \
		--sysconfdir=/etc \
		--with-xslroot="$_xslroot" \
		--with-lg-page="$_pgs" \
		--with-lg-hugepage=21
	make all dist
}

check() {
	make tests
}

package() {
	make install
	install -Dm644 "$builddir"/COPYING "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
}
sha512sums="0bbb77564d767cef0c6fe1b97b705d368ddb360d55596945aea8c3ba5889fbce10479d85ad492c91d987caacdbbdccc706aa3688e321460069f00c05814fae02  jemalloc-5.2.1.tar.bz2"
